---
layout: "default"
root: "/v5.1"
title: "Decoder"
description: "Swift documentation for 'Decoder'"
keywords: ""
---

<div class="intro-declaration"><code class="language-swift">protocol Decoder</code></div><p>A type that can decode values from a native format into in-memory
representations.</p>
<div class="discussion comment"></div><h3>Instance Variables</h3><div id="codingPath-038986a6e6564f0dd444735f926a6ca4" class="declaration"><a class="toggle-link" href="#comment-codingPath-038986a6e6564f0dd444735f926a6ca4">var codingPath</a> <span class="required">Required</span><div class="comment collapse in" id="comment-codingPath-038986a6e6564f0dd444735f926a6ca4"><p>The path of coding keys taken to get to this point in decoding.</p>
<h4>Declaration</h4><code class="language-swift">var codingPath: [CodingKey]</code></div></div><div id="userInfo-49f290d6e8459c53f31f97de37921086" class="declaration"><a class="toggle-link" href="#comment-userInfo-49f290d6e8459c53f31f97de37921086">var userInfo</a> <span class="required">Required</span><div class="comment collapse in" id="comment-userInfo-49f290d6e8459c53f31f97de37921086"><p>Any contextual information set by the user for decoding.</p>
<h4>Declaration</h4><code class="language-swift">var userInfo: [CodingUserInfoKey : Any]</code></div></div><h3>Instance Methods</h3><div id="container_keyedBy-fd27355916e54c796c32f37ccb0f6427" class="declaration"><a class="toggle-link" href="#comment-container_keyedBy-fd27355916e54c796c32f37ccb0f6427">func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer&lt;Key></a> <span class="required">Required</span><div class="comment collapse in" id="comment-container_keyedBy-fd27355916e54c796c32f37ccb0f6427"><p>Returns the data stored in this decoder as represented in a container
keyed by the given key type.</p>
<ul>
<li>parameter type: The key type to use for the container.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">func container&lt;Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer&lt;Key> where Key: CodingKey</code></div></div><div id="singleValueContainer-ed399abe32f4e258623b819368e67ce2" class="declaration"><a class="toggle-link" href="#comment-singleValueContainer-ed399abe32f4e258623b819368e67ce2">func singleValueContainer() throws -> SingleValueDecodingContainer</a> <span class="required">Required</span><div class="comment collapse in" id="comment-singleValueContainer-ed399abe32f4e258623b819368e67ce2"><p>Returns the data stored in this decoder as represented in a container
appropriate for holding a single primitive value.</p>
<h4>Declaration</h4><code class="language-swift">func singleValueContainer() throws -> SingleValueDecodingContainer</code></div></div><div id="unkeyedContainer-23fc7e2badc58fffe60a2c216775e91b" class="declaration"><a class="toggle-link" href="#comment-unkeyedContainer-23fc7e2badc58fffe60a2c216775e91b">func unkeyedContainer() throws -> UnkeyedDecodingContainer</a> <span class="required">Required</span><div class="comment collapse in" id="comment-unkeyedContainer-23fc7e2badc58fffe60a2c216775e91b"><p>Returns the data stored in this decoder as represented in a container
appropriate for holding values with no keys.</p>
<h4>Declaration</h4><code class="language-swift">func unkeyedContainer() throws -> UnkeyedDecodingContainer</code></div></div>